<template>
  <div class="ranking">
    <header>
      <top></top>
      <bottom>
        <left>{{cityname?cityname:'不限'}}<span @click='setflag(0)'>▼</span></left>
        <right>{{cuisine?cuisine:'全部菜系'}}<span @click='setflag(1)'>▼</span></right>
      </bottom>
      <div
        :class="flag?'active':''"
        v-show="flag"
      >
        <div class="left">
          <div
            v-for="(item,index) in list"
            :key="item.id"
            @click="changeitem(index,item.name)"
          >
            <span>{{item.name}}</span>
          </div>
        </div>
        <div
          :class="flagitems?'right-red':''"
          v-show="flagitems"
        >
          <div
            v-for="item in city"
            :key="item.id"
          >
            <span @click="changecityname(item.name)">{{item.name}}</span>
          </div>
        </div>
      </div>
    </header>
    <main>
      <div
        class="item"
        v-for="item in data"
        :key="item.id"
      >
        <div class="item-left">
          <image
            :src="item.logo"
            alt=""
          />
        </div>
        <div class="item-right">
          <div>{{item.shopName}}</div>
          <div>{{item.branchName}}</div>
          <div>日均排队：{{item.queuingNum}}</div>
        </div>
      </div>
    </main>
  </div>
</template>

<script>
import { getRanking, getQueueTop } from "@/service/index";

export default {
  data() {
    return {
      //获取下拉菜单列表
      params: {
        cityId: 19,
        from: 1209
      },
      paramss: {
        cityId: 19,
        areaId: 0,
        bcId: 0,
        cookStyleId: 0,
        page: 1,
        pagesize: 20,
        from: 1209
      },
      list: [],
      flag: false,
      idx: 0,
      areas: [],
      style: [],
      //菜系
      cuisine: "",
      flagitems: false,
      //地址
      city: [],
      cityname: "",
      //进页面获取数据
      data: []
    };
  },

  async onShow() {
    let result = await getRanking(this.params);
    if (result.errno === 0) {
      this.areas = result.data.areas;
      this.style = result.data.style;
    }
    result = await getQueueTop(this.paramss);
    if (result.errno === 0) {
      this.data = result.data.list;
      console.log(this.data);
    }
  },
  methods: {
    setflag(idx) {
      this.flag = true;
      if (idx === 0) {
        this.list = this.areas;
      } else if (idx === 1) {
        this.list = this.style;
      }
    },
    changeitem(idx, name) {
      if (this.list[idx].bc) {
        this.flagitems = true;
        this.city = this.list[idx].bc;
      } else {
        this.flagitems = false;
        this.cuisine = name;
        this.flag = false;
      }
    },
    changecityname(name) {
      this.cityname = name;
      this.flagitems = false;
      this.flag = false;
    },
    result= await getQueueTop(this.paramss),
    if(result.errno===0){
      this.data=result.data.list
      console.log(this.data)
    }
  },
  methods: {
    setflag(idx){
      this.flag=true
      if(idx===0){
        this.list=this.areas
      }else if(idx===1){
         this.list=this.style
      }
    },
    changeitem(idx,name){
      if(this.list[idx].bc){
          this.flagitems=true
          this.city=this.list[idx].bc
        }else{
          this.flagitems=false;
          this.cuisine=name;
          this.flag=false;
        }
    },
    changecityname(name){
      this.cityname=name;
      this.flagitems=false;
      this.flag=false;
    }
  },
};
</script>

<style lang='scss'>
.ranking {
  width: 100%;
  height: 100%;

  header {
    width: 100%;
    height: 400rpx;
    background: url(https://m.mwfile.cn/mm1005/image/20190423/banner-city.png)
      no-repeat center;
    background-size: 100% 400rpx;
    display: flex;
    flex-direction: column;
    top {
      flex: 1;
    }
    bottom {
      width: 100%;
      height: 100rpx;
      display: flex;
      left {
        flex: 1;
        text-align: center;
        line-height: 100rex;
        color: white;
      }
      right {
        flex: 1;
        text-align: center;
        line-height: 100rex;
        color: white;
      }
    }
  }

  main {
    width: 100%;
    background: lightslategrey;
  }
}
.active {
  width: 100%;
  height: 400rpx;
  background: white;
  display: flex;
  .left {
    flex: 1;
    overflow: scroll;
    span {
      display: block;
      width: 100%;
      height: 80rpx;
      line-height: 80rpx;
    }
  }
  .right-red {
    flex: 1;
    overflow: scroll;
    span {
      display: block;
      width: 100%;
      height: 80rpx;
      line-height: 80rpx;
    }
  }
}
.item {
  width: 90%;
  height: 300rpx;
  background: lime;
  margin: 20rpx auto;
  display: flex;
  .item-left {
    flex: 1;
    image {
      width: 100%;
      height: 100%;
      margin: auto;
    }
  }
  .item-right {
    flex: 1;
    background: pink;
  }
}
</style>